﻿using msBsc.AppLogic.DataAlc;
using msBsc.Cls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfVehicleInfo2 : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindControls();
            }
        }
        private void BindControls()
        {
            if (!IsPostBack)
            {

            }
        }

        private void GetVehicleInfo()
        {
            string vehicleId = this.GetParamHtValue("vehicleId");
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataSet ds = vehicleInfo.SelectByIds("", vehicleId);
                if (ds == null)
                {
                    return;
                }
                DataColumn dr = new DataColumn("VEHICLE_BRAND_NAME");
                ds.Tables[0].Columns.Add(dr);
                ds.Tables[0].Rows[0]["VEHICLE_BRAND_NAME"] = Enum.GetName(typeof(msBsc.AppLogic.DataAlc.cls.CommonEnum.VehicleBrandEnum), Convert.ToInt32(ds.Tables[0].Rows[0]["VEHICLE_BRAND"].ToString()));
                DataColumn dr1 = new DataColumn("VEHICLE_SERVICE_TYPE_NAME");
                ds.Tables[0].Columns.Add(dr1);
                ds.Tables[0].Rows[0]["VEHICLE_SERVICE_TYPE_NAME"] = Enum.GetName(typeof(msBsc.AppLogic.DataAlc.cls.CommonEnum.ServiceTypeEnum), Convert.ToInt32(ds.Tables[0].Rows[0]["VEHICLE_SERVICE_TYPE"].ToString()));
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");

                this.ExecJScript(@"setVehicleInfo(" + strJson + ")");
            }
        }
        //服务评论
        public void GetContentList()
        {
            string vehicleId = this.GetParamHtValue("vehicleId");
            if (string.IsNullOrEmpty(vehicleId))
            {
                return;
            }
            string pageI = this.GetParamHtValue("pageIndex");
            int pageIndex = 0;
            int.TryParse(pageI, out pageIndex);

            if (pageIndex < 1)
            {
                return;
            }
            //获取车辆评论 信息
            using (msBsc.AppLogic.DataAlc.CBizCustomerEvlution CBEComments = new AppLogic.DataAlc.CBizCustomerEvlution())
            {
                DataSet dsContent = CBEComments.GetCommentsInfo(20, pageIndex, vehicleId);
                if (dsContent == null || dsContent.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dsContent.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp').html();
                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#commentMsg').html(render);loginImg();

                            });jsPage('divPage', " + dsContent.Tables[0].Rows[0]["DATACOUNT"] + ", " + 20 + ", " + pageIndex + ", 'goPage');");
            }
        }

        //加载图片
        public void GetCommentImgs()
        {
            string evlutionid = this.GetParamHtValue("evlutionid");
            if (string.IsNullOrEmpty(evlutionid))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizEvlutionImages CBEComments = new AppLogic.DataAlc.CBizEvlutionImages())
            {
                DataSet dsImgs = CBEComments.GetEvlutionImages(evlutionid);
                if (dsImgs == null || dsImgs.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dsImgs.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript("imgView(" + retJson + ",'" + evlutionid + "');");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "getVehicleInfo")
            {
                GetVehicleInfo();
            }
            else if (this.strAction == "getmsg")
            {
                GetContentList();
            }
            else if (this.strAction == "getimgs")
            {
                GetCommentImgs();
            }
        }
    }
}